home *** CD-ROM | disk | FTP | other *** search
- Path: hearst.acc.Virginia.EDU!adastra!mbs
- Newsgroups: comp.sys.amiga.programmer
- From: mbs@adastra.cvl.va.us (Michael B. Smith)
- Subject: Re: Sorting a list
- References: <272.6650T63T1340@sn.no> <314E9DCA.2E9E@cs.ruu.nl>
- X-NewsReader: GRn 3.0f March 8, 1996
- MIME-Version: 1.0
- Content-Type: text/plain; charset=iso-8859-1
- Content-Transfer-Encoding: 8bit
- Message-ID: <mbs.4a6m@adastra.cvl.va.us>
- Date: Wed, 20 Mar 96 07:11:50 EDT
- Organization: Only if you insist...
-
- > Christopher Naas wrote:
- > > What's the absolutely fastest algorithm for sorting a List with around 1000
- > > items alphabetically?
-
- I went through a fairly exhaustive search around a year ago, to try
- to find ways to significantly speed up GRn sorting. I found the
- quickest practical way (without significant setup and teardown time)
- to be an iterative quicksort.
-
- void
- SortList (struct List *list)
- {
- int
- count = CountListEntries (list);
- struct Node
- **n;
-
- PROC ("SortList");
-
- if (count < 2)
- {
- D (("exit, count %ld\n", count));
- return;
- }
-
- n = AllocVec (count * sizeof (struct Node *), 0);
- if (!n)
- {
- /* gulp! */
- D (("exit, couldn't allocate %ld bytes\n", count * sizeof (struct Node *)));
- return;
- }
-
- SetupList (list, n, count);
- qsort (n, count, sizeof (struct Node *), CompareName);
- FixArray (list, n, count);
-
- FreeVec (n);
-
- D (("exit\n"));
- return;
- }
-
- --
- // Michael B. Smith
- \X/ mbs@adastra.cvl.va.us
-